package cn.edu.xjtu.competiton.力扣.双周赛.biweekly77;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Hydrion-QLz
 * @date 2022-04-30 23:11
 * @description https://leetcode-cn.com/contest/biweekly-contest-77/problems/count-prefixes-of-a-given-string/
 */
public class first {
    public int countPrefixes(String[] words, String s) {
        Set<String> set = new HashSet<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            sb.append(s.charAt(i));
            set.add(sb.toString());
        }

        int ans = 0;
        for (int i = 0; i < words.length; i++) {
            if (set.contains(words[i])) {
                ans++;
            }
        }
        return ans;
    }
}
